#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/rope>
#define rep(i,l,r) for(int i=(l),i##end=(r);i<=i##end;++i)
#define per(i,r,l) for(int i=(r),i##end=(l);i>=i##end;--i)
#define ll long long
//#define int ll
#define double long double
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define popcnt __builtin_popcount
#define rbtree(way) tree<way,null_type,less<way>,rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
const int maxn=1e6+10,maxm=1e6+10,mod=998244353,inf=INT_MAX;
inline int ksm(int x,int k,int mod=mod){
	int ans=1;
	for(x%=mod;k;k>>=1,x=x*x%mod) if(k&1) ans=ans*x%mod;
	return ans;
}

namespace Fastio {
const int L = 1 << 20;
inline char gc() {
    static char buf[L], *l = buf, *r = buf;
    if (l == r)
        r = (l = buf) + fread(buf, 1, L, stdin);
    return (l == r) ? EOF : *l++;
}
char obuf[L], *p = obuf;
inline void pc(char c) {
    if (p == obuf + L)
        fwrite(obuf, 1, L, stdout), p = obuf;
    *p++ = c;
}
inline void flush() { fwrite(obuf, 1, p - obuf, stdout); }
struct Reader {
    template <typename T>
    inline Reader& operator>>(T& x) {
        x = 0;
        short f = 1;
        char c = gc();
        while (!isdigit(c)) {
            if (c == '-')
                f = -1;
            c = gc();
        }
        while (isdigit(c)) x = 10 * x + (c - '0'), c = gc();
        x *= f;
        return *this;
    }
    Reader() {}
} cin;
struct Writer {
    template <typename T>
    inline Writer& operator<<(T x) {
        if (x < 0)
            pc('-'), x = -x;
        static short tp = 0, s[40];
        do
            s[++tp] = x % 10, x /= 10;
        while (x);
        while (tp) pc(s[tp--] + '0');
        return *this;
    }
    inline Writer& operator<<(const char* s) {
        int i = 0;
        while (s[i]) pc(s[i++]);
        return *this;
    }
    inline Writer& operator<<(char c) {
        pc(c);
        return *this;
    }
    Writer() {}
    ~Writer() { flush(); }
} cout;
#define cin Fastio::cin
#define cout Fastio::cout
}

int n,q;
namespace sgtree{
struct node{
	int ls,rs,sz;
}sg[maxn*20];
int tot,rot[maxn];

#define ls(id) sg[id].ls
#define rs(id) sg[id].rs
inline void pushup(int id){sg[id].sz=sg[ls(id)].sz+sg[rs(id)].sz;}
void insert(int id,int l,int r,int x){
	++sg[id].sz;
	if(l==r) return;
	int mid=l+r>>1;
	if(x<=mid) sg[++tot]=sg[ls(id)],ls(id)=tot,insert(ls(id),l,mid,x);
	else sg[++tot]=sg[rs(id)],rs(id)=tot,insert(rs(id),mid+1,r,x);
}
int merge(int x,int y){
	if(!x||!y) return x|y;
	sg[++tot]=sg[x],x=tot;
	return ls(x)=merge(ls(x),ls(y)),rs(x)=merge(rs(x),rs(y)),pushup(x),x;
}
int query(int id,int l,int r,int lq,int rq){
	if(!id) return 0;
	if(sg[id].sz==r-l+1) return min(r,rq)-max(l,lq)+1;
	if(lq<=l&&r<=rq) return sg[id].sz;
	int mid=l+r>>1,ans=0;
	if(lq<=mid) ans+=query(ls(id),l,mid,lq,rq);
	if(rq>mid) ans+=query(rs(id),mid+1,r,lq,rq);
	return ans;
}
#undef ls
#undef rs
}
using namespace sgtree;

vector<pii> e[maxn];
int dft,dfn[maxn],dfid[maxn],fa[maxn],lt[maxn],sz[maxn],hs[maxn],dep[maxn];
ll ans,suma[maxn];

void dfs(int x){
	sz[x]=1,rot[x]=++tot,insert(rot[x],1,n,x);
	for(pii i:e[x]) if(i.fi!=fa[x]) suma[i.fi]=i.se+suma[x],dep[i.fi]=dep[x]+1,fa[i.fi]=x,
		dfs(i.fi),sz[x]+=sz[i.fi],sz[i.fi]>sz[hs[x]]?hs[x]=i.fi:0,rot[x]=merge(rot[x],rot[i.fi]);
}
void dfs1(int x){
	dfid[dfn[x]=++dft]=x,!lt[x]?lt[x]=x:0,hs[x]?lt[hs[x]]=lt[x],dfs1(hs[x]),0:0;
	for(pii i:e[x]) if(i.fi!=fa[x]&&i.fi!=hs[x]) dfs1(i.fi);
}
inline int lca(int u,int v){
	for(;lt[u]!=lt[v];dep[lt[u]]<dep[lt[v]]?v=fa[lt[v]]:u=fa[lt[u]]);
	return dep[u]<dep[v]?u:v;
}

signed main(){
	freopen("memory.in","r",stdin),freopen("memory.out","w",stdout);
	cin>>n>>q;
	rep(i,1,n-1){
		int u,v,w;
		cin>>u>>v>>w,e[u].pb({v,w}),e[v].pb({u,w});
	}
	dfs(1),dfs1(1);
	rep(o,1,q){
		ll p,L,R;
		int u,v,len,k=0,sure=0;
		cin>>p>>L>>R,p^=ans,L^=ans,R^=ans,ans=0,u=L,v=p,len=R-L+1;
		for(;lt[u]!=lt[v];) if(dep[lt[u]]>dep[lt[v]]){
			if(query(rot[lt[u]],1,n,L,R)==len){
				for(int l=dfn[lt[u]],r=dfn[u],mid=l+r>>1;l<=r;mid=l+r>>1)
					if(query(rot[dfid[mid]],1,n,L,R)==len) k=dfid[mid],l=mid+1;
					else r=mid-1;
				sure=1;
				break;
			}
			u=fa[lt[u]];
		}
		else{
			if(!query(rot[v],1,n,L,R)) if(!query(rot[lt[v]],1,n,L,R)) k=fa[lt[v]];
			else{
				for(int l=dfn[lt[v]],r=dfn[v],mid=l+r>>1;l<=r;mid=l+r>>1)
					if(!query(rot[dfid[mid]],1,n,L,R)) k=fa[dfid[mid]],r=mid-1;
					else l=mid+1;
				sure=1;
				break;
			}
			v=fa[lt[v]];
		}
		if(!sure) if(dep[u]<dep[v]&&!query(rot[v],1,n,L,R))
			for(int l=dfn[hs[u]],r=dfn[v],mid=l+r>>1;l<=r;mid=l+r>>1)
				if(!query(rot[dfid[mid]],1,n,L,R)) k=fa[dfid[mid]],r=mid-1;
				else l=mid+1;
		else if(dep[u]>dep[v]&&query(rot[hs[v]],1,n,L,R))
			for(int l=dfn[hs[v]],r=dfn[u],mid=l+r>>1;l<=r;mid=l+r>>1)
				if(query(rot[dfid[mid]],1,n,L,R)==len) k=dfid[mid],l=mid+1;
				else r=mid-1;
		if(k) ans=suma[k]+suma[p]-(suma[lca(k,p)]<<1);
		cout<<ans<<'\n';
	}
	return 0;
}/*
10 1
2 1 9907
3 2 8329
4 2 8402
5 4 3636
6 4 8747
7 4 3080
8 6 780
9 6 5414
10 9 3545
7 1 2

*/
